<?php

namespace App\Http\Controllers\OA;

use App\Http\Controllers\Controller;
use App\Http\Controllers\Logic\MatterLogic;
use Illuminate\Http\Request;

/**
 * 物料
 */
class MatterController extends Controller
{
    //添加物料
    public function matterEdit(Request $request)
    {
        try{
            $rules = [
                'order_id'=>'required|numeric',
                'type'=>'required|string|nullable',
                'method'=>'required|string|nullable',
                'pay_method'=>'required|string|nullable',
                'currency'=>'required|string|nullable',
                'material'=>'sometimes|string|nullable',
                'money'=>'sometimes|nullable',
                'tax'=>'sometimes|string|nullable',
                'unit'=>'sometimes|string|nullable',
                'number'=>'sometimes|required',
                'desc'=>'sometimes|string|nullable',
                'files'=>'sometimes|array|nullable',
                'id'=>'required|numeric'
            ];
            $params = $this->mergeRequest($request);
            $this->verify($params,$rules);

            $result = (new MatterLogic())->addMatter($params);
            ret_json('ok','物料添加成功');
        }catch (\Exception $e){
            ret_json('err',$e->getMessage());
        }
    }

    //我的竞价
    public function getMyPriceList(Request $request)
    {
        try{
            $rules = [
                'order_id'=>'required|numeric|exists:orders,id',
            ];
            $this->verify($request->all(),$rules);
            $params = $this->mergeRequest($request);
            $list = (new MatterLogic())->getMyPriceList($params);
            ret_json('ok','ok',$list);
        }catch (\Exception $e){
            ret_json('err',$e->getMessage());
        }
    }

    //竞价结果
    public function getMyPriceResult(Request $request)
    {
        try{
            $rules = [
                'order_id'=>'required|numeric|exists:orders,id',
            ];
            $this->verify($request->all(),$rules);
            $params = $this->mergeRequest($request);
            $info = (new MatterLogic())->getMyPriceResult($params);
            ret_json('ok','ok',$info);
        }catch (\Exception $e){
            ret_json('err',$e->getMessage());
        }
    }


}
